home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / libhoward / part05 < prev    next >
Encoding:
Text File  |  1989-09-30  |  46.1 KB  |  1,629 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v08i083: libhoward portability library, part 5 of 9
  3. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Reply-To: howard@dahlbeck.ericsson.se (Howard Gayle)
  5.  
  6. Posting-number: Volume 8, Issue 83
  7. Submitted-by: howard@dahlbeck.ericsson.se (Howard Gayle)
  8. Archive-name: libhoward/part05
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # If this archive is complete, you will see the following message at the end:
  17. #        "End of archive 5 (of 9)."
  18. # Contents:  getlin.3 getpwf.3 getpwf.c ma2u.c ma2ul.c malf.c
  19. #   mkLibcLims.b msgfn.c smp.3 smp2l.c smp2u.c smp2ul.c
  20. # Wrapped by howard@hasse on Mon Sep 25 07:08:10 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'getlin.3' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'getlin.3'\"
  24. else
  25. echo shar: Extracting \"'getlin.3'\" \(3505 characters\)
  26. sed "s/^X//" >'getlin.3' <<'END_OF_FILE'
  27. X.\" @(#)$Header: getlin.3,v 1.7 89/07/05 07:31:35 howard Exp $
  28. X.TH GETLIN "3 -lhoward" "$Revision: 1.7 $" "Howard\'s C library" "Howard\'s C library"
  29. X.SH NAME
  30. Xgetlin, getlic \- read one line from a stream
  31. X.SH SYNOPSIS
  32. X.nf
  33. X.BR "#include <" stdio.h ">"
  34. X.BR "#include <" howard/port.h ">"
  35. X.fi
  36. X.LP
  37. X.RI "bStrT getlin (" linebuf ", " bufsize ", " infile
  38. X.RI ", " filename ", " lineno ", " tabwidth
  39. X)
  40. X.nf
  41. X.RI "bStrT " linebuf ";"
  42. X.BI "unsigned " bufsize;
  43. X.RI "streamT " infile ";"
  44. X.RI "bStrT " filename ";"
  45. X.BI "unsigned *" lineno;
  46. X.BI "unsigned " tabwidth;
  47. X.fi
  48. X.LP
  49. X.RI "bStrT getlic (" linebuf ", " bufsize ", " infile
  50. X.RI ", " filename ", " lineno ", " tabwidth
  51. X.RI ", " comment ")"
  52. X.nf
  53. X.RI "bStrT " linebuf ";"
  54. X.BI "unsigned " bufsize;
  55. X.RI "streamT " infile ";"
  56. X.RI "bStrT " filename ";"
  57. X.BI "unsigned *" lineno;
  58. X.BI "unsigned " tabwidth;
  59. X.RI "rcharT " comment ";"
  60. X.SH COPYRIGHT
  61. XCopyright \(co 1989 Howard Lee Gayle
  62. X.SH DESCRIPTION
  63. X.I Getlin
  64. Xattempts to read one line from the Standard I/O Library stream
  65. X.I infile.
  66. XOn success, the line is stored in the buffer to which
  67. X.I linebuf
  68. Xpoints.
  69. XThe newline character at the end of the line is removed.
  70. XThe line is NUL terminated.
  71. XThe current line number, to which
  72. X.I lineno
  73. Xpoints, is incremented.
  74. XIf
  75. X.I tabwidth
  76. Xis zero then tabs are not expanded.
  77. XOtherwise, tabs are expanded into spaces, and
  78. X.I tabwidth
  79. Xgives the spacing between tab columns.
  80. X.PP
  81. X.I Getlic
  82. Xis like
  83. X.IR getlin ,
  84. Xexcept that the final
  85. X.I comment
  86. Xargument is taken to be a character indicating the start of a
  87. Xcomment that continues until the end of a line.
  88. X.I Getlic
  89. Xstrips comments.
  90. XIt then strips any spaces or tabs at the ends of lines.
  91. XIt does not return blank lines.
  92. X.SH ERRORS
  93. X.I Getlic
  94. Xand
  95. X.I getlin
  96. Xcheck for several errors.
  97. XIn each case,
  98. X.I malf1
  99. Xis called to print an appropriate error message and exit.
  100. XThe file name
  101. X.I filename
  102. Xis included in the error messages.
  103. XThe following errors are checked:
  104. X.IP -
  105. XThe input line would overflow the buffer, whose size is given by
  106. X.I bufsize.
  107. X.IP -
  108. XRead error.
  109. X.IP -
  110. XEnd of file in the middle of a line.
  111. XThat is, the file is not empty, and the last character is not a newline.
  112. X.IP -
  113. XNUL in file.
  114. X.SH RETURNS
  115. XOn success,
  116. X.I getlic
  117. Xand
  118. X.I getlin
  119. Xreturn a pointer to the NUL terminator of the line read into
  120. X.I linebuf.
  121. XOn normal end of file,
  122. Xthey return NULBSTR.
  123. XThey do not return on error.
  124. X.SH EXAMPLE
  125. XTo copy standard input to standard output and expand tabs into spaces:
  126. X.nf
  127. X   unsigned     ln = 0;
  128. X   static byteT l[1024];
  129. X
  130. X   while (NULBSTR != getlin (l, 1024, stdin, "Standard Input", &ln, 8))
  131. X      (void) puts (l);
  132. X.fi
  133. X.SH "SEE ALSO"
  134. X.IR intro (3S),
  135. X.IR malf "(3 -lhoward)."
  136. X.SH BUGS
  137. XOverflow of the line number is not checked.
  138. X.SH LICENSE
  139. XThis program is free software; you can redistribute it and/or modify
  140. Xit under the terms of the GNU General Public License version 1,
  141. Xas published by the Free Software Foundation.
  142. X.PP
  143. XThis program is distributed in the hope that it will be useful,
  144. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  145. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  146. XGNU General Public License for more details.
  147. X.PP
  148. XYou should have received a copy of the GNU General Public License
  149. Xalong with this program; if not, write to the Free Software
  150. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  151. X.SH AUTHOR
  152. XHoward Gayle,
  153. XTN/ETX/T/BG,
  154. XEricsson Telecom AB,
  155. XS-126 25 Stockholm,
  156. XSweden,
  157. Xhoward@ericsson.se,
  158. Xuunet!ericsson.se!howard,
  159. XPhone: +46 8 719 5565,
  160. XFAX: +46 8 719 9598,
  161. XTelex: 14910 ERIC S
  162. END_OF_FILE
  163. if test 3505 -ne `wc -c <'getlin.3'`; then
  164.     echo shar: \"'getlin.3'\" unpacked with wrong size!
  165. fi
  166. # end of 'getlin.3'
  167. fi
  168. if test -f 'getpwf.3' -a "${1}" != "-c" ; then 
  169.   echo shar: Will not clobber existing file \"'getpwf.3'\"
  170. else
  171. echo shar: Extracting \"'getpwf.3'\" \(2847 characters\)
  172. sed "s/^X//" >'getpwf.3' <<'END_OF_FILE'
  173. X.\" $Header: getpwf.3,v 1.2 89/08/21 08:43:59 howard Exp $
  174. X.TH GETPWF "3 -lhoward" "$Revision: 1.2 $" "Howard\'s C library" "Howard\'s C library"
  175. X.SH NAME
  176. Xgetpwf \- copy full name of user from password file entry
  177. X.SH SYNOPSIS
  178. X.nf
  179. X.BR "#include <" stdio.h ">"
  180. X.BR "#include <" pwd.h ">"
  181. X.BR "#include <" howard/port.h ">"
  182. X.BR "#include <" howard/malf.h ">"
  183. X.fi
  184. X.LP
  185. XbStrT getpwf (
  186. X.IR passwdPtr ,
  187. X.IR buffer )
  188. X.nf
  189. X.BI "struct passwd *" passwdPtr;
  190. X.RI "bStrT " buffer ;
  191. X.fi
  192. X.SH COPYRIGHT
  193. XCopyright \(co 1989 Howard Lee Gayle
  194. X.SH DESCRIPTION
  195. X.I passwdPtr
  196. Xpoints to a password file entry for a user.
  197. X.I getpwf
  198. Xcopies the user's full (real) name into the area to which
  199. X.I buffer
  200. Xpoints.
  201. XIt does this in the face of BSD asterisk, ampersand, and comma kludges.
  202. X.SH RETURNS
  203. XOn success, a pointer to the NUL in
  204. X.I buffer
  205. Xat the end of the copied full name.
  206. XNULL if the full name is empty.
  207. X.SH EXAMPLE
  208. XThe password entry
  209. X.nf
  210. X   howard::159:13:*& Gayle,TN 15028,95565,:/u5/howard:/bin/csh
  211. X.fi
  212. Xresults in "Howard Gayle" in
  213. X.IR buffer .
  214. X.SH "SEE ALSO"
  215. X.IR getpwent (3),
  216. X.IR userfn "(3 \-lhoward)."
  217. X.SH BUGS
  218. XThe BSD asterisk convention is a kludge.
  219. XIt is a convention for password aging.
  220. XAn asterisk at the beginning of the GECOS field is ignored by
  221. Xall software except
  222. X.IR passwd (1),
  223. Xwhich removes it when the password is changed.
  224. XBy periodically setting an asterisk on all password entries, it
  225. Xis possible to see which users have not changed their passwords
  226. Xwithin a given time.
  227. X.PP
  228. XThe BSD ampersand convention is a kludge.
  229. XAn ampersand in the GECOS field expands into a capitalized copy
  230. Xof the login name.
  231. XUsers whose login names are one of their real names can thus
  232. Xhave slightly shorter password entries.
  233. XBig deal!
  234. X.PP
  235. XThe BSD comma convention is a kludge.
  236. XBSD treats the GECOS field as a comma-separated list of
  237. Xsubfields: full name, room number, office phone, home phone.
  238. XThese additional data should go somewhere else.
  239. XThis kludge eliminates full names with commas,
  240. X.I e.g.
  241. XHenry Ford, Jr.
  242. XThis is probably why he never had a UNIX login.
  243. X.SH LICENSE
  244. XThis program is free software; you can redistribute it and/or modify
  245. Xit under the terms of the GNU General Public License version 1,
  246. Xas published by the Free Software Foundation.
  247. X.PP
  248. XThis program is distributed in the hope that it will be useful,
  249. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  250. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  251. XGNU General Public License for more details.
  252. X.PP
  253. XYou should have received a copy of the GNU General Public License
  254. Xalong with this program; if not, write to the Free Software
  255. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  256. X.SH AUTHOR
  257. XHoward Gayle,
  258. XTN/ETX/T/BG,
  259. XEricsson Telecom AB,
  260. XS-126 25 Stockholm,
  261. XSweden,
  262. Xhoward@ericsson.se,
  263. Xuunet!ericsson.se!howard,
  264. XPhone: +46 8 719 5565,
  265. XFAX: +46 8 719 9598,
  266. XTelex: 14910 ERIC S
  267. END_OF_FILE
  268. if test 2847 -ne `wc -c <'getpwf.3'`; then
  269.     echo shar: \"'getpwf.3'\" unpacked with wrong size!
  270. fi
  271. # end of 'getpwf.3'
  272. fi
  273. if test -f 'getpwf.c' -a "${1}" != "-c" ; then 
  274.   echo shar: Will not clobber existing file \"'getpwf.c'\"
  275. else
  276. echo shar: Extracting \"'getpwf.c'\" \(3428 characters\)
  277. sed "s/^X//" >'getpwf.c' <<'END_OF_FILE'
  278. X/*
  279. X * getpwf - copy full name of user from password file entry
  280. X */
  281. X
  282. X#ifndef lint
  283. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  284. X#endif lint
  285. X
  286. X/*
  287. X * This program is free software; you can redistribute it and/or modify
  288. X * it under the terms of the GNU General Public License version 1,
  289. X * as published by the Free Software Foundation.
  290. X *
  291. X * This program is distributed in the hope that it will be useful,
  292. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  293. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  294. X * GNU General Public License for more details.
  295. X *
  296. X * You should have received a copy of the GNU General Public License
  297. X * along with this program; if not, write to the Free Software
  298. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  299. X */
  300. X
  301. X#include <stdio.h>
  302. X#include <howard/port.h>
  303. X#include <howard/version.h>
  304. X
  305. XMODVER ("@(#)$Header: getpwf.c,v 1.2 89/08/20 11:05:20 howard Exp $");
  306. X
  307. X#include <ctype.h>
  308. X#include <pwd.h>
  309. X#include <howard/malf.h>
  310. X#include <howard/registers.i>
  311. X
  312. XPUBLIC bStrT getpwf (pwp, fnb)
  313. XR3 struct passwd *pwp; /* Points to password entry.*/
  314. XR4 bStrT          fnb; /* Store full name here.*/
  315. X
  316. X
  317. X/* Function:
  318. X *    
  319. X * Algorithm:
  320. X *    Copy byte-by-byte.  Skip *. Expand &.
  321. X * Returns:
  322. X *    Pointer to EOS terminator in fnb[].
  323. X * Notes:
  324. X *    1) In 4.3BSD, and perhaps other systems, an ampersand (&) in the
  325. X *       GECOS field means the capitalized login name.  When the login
  326. X *       name is the same as the user's first or last name, this makes
  327. X *       the password entry slightly shorter.
  328. X *    2) Some systems treat the GECOS field as many comma-separated fields.
  329. X *       The full name comes first.
  330. X *    3) Some systems use an asterisk (*) in the beginning of the GECOS
  331. X *       field for password aging.  The passwd command removes the *
  332. X *       when changing passwords.  So, to enforce e.g. yearly password
  333. X *       changes, you put a * into everyone's GECOS field at the beginning
  334. X *       of the year, and users who still have a * at the end of the year
  335. X *       are reminded to change their passwords.  Everything else ignores
  336. X *       the *.
  337. X */
  338. X{
  339. XR1 bStrT  p;  /* Steps through GECOS field.*/
  340. XR5 bStrT  p1; /* Steps through login name.*/
  341. XR2 bStrT  p2; /* Steps through fnb[].*/
  342. XR6 rcharT b;  /* First byte of login name.*/
  343. X
  344. Xif (((struct passwd *) NULL) == pwp) malf1 ("getpwf: no password pointer");
  345. Xif (NULBSTR == fnb)                  malf1 ("getpwf: no buffer");
  346. Xp = (bStrT) pwp->pw_gecos;
  347. Xif (NULBSTR == p) return (p);
  348. Xif ('*' == B(*p)) ++p;
  349. Xfor (p2 = fnb; (EOS != B(*p)) && (',' != B(*p)); ++p)
  350. X   {
  351. X   if ('&' != B(*p))
  352. X      *p2++ = B(*p);
  353. X   else
  354. X      {
  355. X      p1 = (bStrT) pwp->pw_name;
  356. X      b = B(*p1);
  357. X      if (isascii (b) && islower (b)) b = toupper (b);
  358. X      *p2++ = b;
  359. X      for (++p1; EOS != B(*p1); ++p1)
  360. X         *p2++ = B(*p1);
  361. X      }
  362. X   }
  363. Xif (p2 == fnb) return (NULBSTR);
  364. X*p2 = EOS;
  365. Xreturn (p2);
  366. X}
  367. X
  368. X#ifdef TEST
  369. X#include <howard/usage.h>
  370. X
  371. XMAINVER ("@(#)$Header: getpwf.c,v 1.2 89/08/20 11:05:20 howard Exp $");
  372. XUSAGE ("login-name");
  373. X
  374. X#include <howard/malf.h>
  375. X
  376. XPUBLIC int main (argc, argv)
  377. Xint    argc; /* Number of arguments.*/
  378. XbStrT *argv; /* Points to array of argument strings.*/
  379. X{
  380. XbyteT fnb[1024]; /* Full name buffer.*/
  381. X
  382. Xif (2 != argc) usage();
  383. X(void) getpwf (getpwnam ((cStrT) argv[1]), fnb);
  384. XPUTS (fnb);
  385. Xmfflush (stdout, S("Standard Output"));
  386. Xexit (SUCCESS);
  387. X
  388. X#ifdef lint
  389. Xreturn (SUCCESS);
  390. X#endif
  391. X}
  392. X#endif
  393. END_OF_FILE
  394. if test 3428 -ne `wc -c <'getpwf.c'`; then
  395.     echo shar: \"'getpwf.c'\" unpacked with wrong size!
  396. fi
  397. # end of 'getpwf.c'
  398. fi
  399. if test -f 'ma2u.c' -a "${1}" != "-c" ; then 
  400.   echo shar: Will not clobber existing file \"'ma2u.c'\"
  401. else
  402. echo shar: Extracting \"'ma2u.c'\" \(3073 characters\)
  403. sed "s/^X//" >'ma2u.c' <<'END_OF_FILE'
  404. X/*
  405. X * ma2u - convert Ada-syntax integer literal to unsigned, handle errors
  406. X */
  407. X
  408. X#ifndef lint
  409. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  410. X#endif lint
  411. X
  412. X/*
  413. X * This program is free software; you can redistribute it and/or modify
  414. X * it under the terms of the GNU General Public License version 1,
  415. X * as published by the Free Software Foundation.
  416. X *
  417. X * This program is distributed in the hope that it will be useful,
  418. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  419. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  420. X * GNU General Public License for more details.
  421. X *
  422. X * You should have received a copy of the GNU General Public License
  423. X * along with this program; if not, write to the Free Software
  424. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  425. X */
  426. X
  427. X#include <stdio.h>
  428. X#include <howard/port.h>
  429. X#include <howard/version.h>
  430. X
  431. XMODVER ("@(#)$Header: ma2u.c,v 1.4 89/08/12 09:37:32 howard Exp $");
  432. X
  433. X#include <errno.h>
  434. X#include <limits.h>
  435. X#include <string.h>
  436. X#include <howard/a2.h>
  437. X#include <howard/malf.h>
  438. X#include <howard/registers.i>
  439. X
  440. XPUBLIC unsigned ma2u (str, lim, synok, fn, end)
  441. X   bStrT  str;   /* Input string.*/
  442. X   bStrT  lim;   /* Don't pass this.*/
  443. X   boolT  synok; /* Accept non-fatal syntax errors.*/
  444. X   bStrT  fn;    /* Field name, for error messages.*/
  445. XR2 bStrT *end;   /* End pointer stored here.*/
  446. X
  447. X/* Function:
  448. X *    
  449. X * Algorithm:
  450. X *    Call a2u() then switch on return code.
  451. X * Returns:
  452. X *    
  453. X * Notes:
  454. X *    
  455. X */
  456. X{
  457. X   bStrT    ep; /* a2u() stores pointer to end of string here.*/
  458. X   unsigned u;  /* a2u() stores its result here.*/
  459. XR3 int      p1; /* Precision for printing str (up to syntax error).*/
  460. XR4 int      p2; /* Precision for printing str (after syntax error).*/
  461. XR1 int      s;  /* Return code.*/
  462. X
  463. Xs = a2u (str, lim, synok, &u, &ep);
  464. Xswitch (s)
  465. X   {
  466. X   case SUCCESS:
  467. X      break;
  468. X   case EDOM:
  469. X      p1 = ep - str;
  470. X      p2 = ((NULBSTR == lim) ? strlen (str) : lim - str) - p1;
  471. X      malf1 ("%s [%.*s|%.*s]: syntax error", fn, p1, str, p2, ep);
  472. X      break;
  473. X   case ERANGE:
  474. X      p1 = ((NULBSTR == lim) ? INT_MAX : lim - str);
  475. X      malf1 ("%s [%.*s] not in range [0, %u]", fn, p1, str, UINT_MAX);
  476. X      break;
  477. X   case EINVAL:
  478. X      if (NULBSTR == str) malf1 ("ma2u: null string argument");
  479. X      /* Falls through.*/
  480. X   default:
  481. X      malf1 ("ma2u: impossible error %d", s);
  482. X   }
  483. Xif (((bStrT *) NULL) != end) *end = ep;
  484. Xreturn (u);
  485. X}
  486. X
  487. X#ifdef TEST
  488. X#include <howard/usage.h>
  489. X
  490. XMAINVER ("@(#)$Header: ma2u.c,v 1.4 89/08/12 09:37:32 howard Exp $");
  491. XUSAGE ("integer-numeric-literal [limit]");
  492. X
  493. XPUBLIC int main (argc, argv)
  494. Xint    argc; /* Number of arguments.*/
  495. XbStrT *argv; /* Points to array of argument strings.*/
  496. X{
  497. XbStrT end; /* Points to end of string.*/
  498. Xunsigned u; /* Returned by ma2u().*/
  499. X
  500. Xif (argc < 2) usage();
  501. Xu = ma2u (argv[1], (2 == argc) ? NULBSTR : &argv[1][atoi (argv[2])], FALSE,
  502. X          S("integer-numeric-literal"), &end);
  503. XPRINTF ("8#%o#\t10#%u#\t16#%X#\t%s\n", u, u, u, end);
  504. Xmfflush (stdout, "Standard Output");
  505. Xexit (SUCCESS);
  506. X
  507. X#ifdef lint
  508. Xreturn (SUCCESS);
  509. X#endif
  510. X}
  511. X#endif
  512. END_OF_FILE
  513. if test 3073 -ne `wc -c <'ma2u.c'`; then
  514.     echo shar: \"'ma2u.c'\" unpacked with wrong size!
  515. fi
  516. # end of 'ma2u.c'
  517. fi
  518. if test -f 'ma2ul.c' -a "${1}" != "-c" ; then 
  519.   echo shar: Will not clobber existing file \"'ma2ul.c'\"
  520. else
  521. echo shar: Extracting \"'ma2ul.c'\" \(3081 characters\)
  522. sed "s/^X//" >'ma2ul.c' <<'END_OF_FILE'
  523. X/*
  524. X * ma2ul - convert Ada-syntax integer literal to long unsigned, handle errors
  525. X */
  526. X
  527. X#ifndef lint
  528. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  529. X#endif lint
  530. X
  531. X/*
  532. X * This program is free software; you can redistribute it and/or modify
  533. X * it under the terms of the GNU General Public License version 1,
  534. X * as published by the Free Software Foundation.
  535. X *
  536. X * This program is distributed in the hope that it will be useful,
  537. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  538. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  539. X * GNU General Public License for more details.
  540. X *
  541. X * You should have received a copy of the GNU General Public License
  542. X * along with this program; if not, write to the Free Software
  543. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  544. X */
  545. X
  546. X#include <stdio.h>
  547. X#include <howard/port.h>
  548. X#include <howard/version.h>
  549. X
  550. XMODVER ("@(#)$Header: ma2ul.c,v 1.3 89/08/12 09:56:17 howard Exp $");
  551. X
  552. X#include <errno.h>
  553. X#include <limits.h>
  554. X#include <string.h>
  555. X#include <howard/a2.h>
  556. X#include <howard/malf.h>
  557. X#include <howard/registers.i>
  558. X
  559. XPUBLIC ulongT ma2ul (str, lim, synok, fn, end)
  560. X   bStrT  str;   /* Input string.*/
  561. X   bStrT  lim;   /* Don't pass this.*/
  562. X   boolT  synok; /* Accept non-fatal syntax errors.*/
  563. X   bStrT  fn;    /* Field name, for error messages.*/
  564. XR2 bStrT *end;   /* End pointer stored here.*/
  565. X
  566. X/* Function:
  567. X *    
  568. X * Algorithm:
  569. X *    Call a2ul() then switch on return code.
  570. X * Returns:
  571. X *    
  572. X * Notes:
  573. X *    
  574. X */
  575. X{
  576. X   bStrT  ep; /* a2ul() stores pointer to end of string here.*/
  577. X   ulongT u;  /* a2ul() stores its result here.*/
  578. XR3 int    p1; /* Precision for printing str (up to syntax error).*/
  579. XR4 int    p2; /* Precision for printing str (after syntax error).*/
  580. XR1 int    s;  /* Return code.*/
  581. X
  582. Xs = a2ul (str, lim, synok, &u, &ep);
  583. Xswitch (s)
  584. X   {
  585. X   case SUCCESS:
  586. X      break;
  587. X   case EDOM:
  588. X      p1 = ep - str;
  589. X      p2 = ((NULBSTR == lim) ? strlen (str) : lim - str) - p1;
  590. X      malf1 ("%s [%.*s|%.*s]: syntax error", fn, p1, str, p2, ep);
  591. X      break;
  592. X   case ERANGE:
  593. X      p1 = ((NULBSTR == lim) ? INT_MAX : lim - str);
  594. X      malf1 ("%s [%.*s] not in range [0, %lu]", fn, p1, str, ULONG_MAX);
  595. X      break;
  596. X   case EINVAL:
  597. X      if (NULBSTR == str) malf1 ("ma2ul: null string argument");
  598. X      /* Falls through.*/
  599. X   default:
  600. X      malf1 ("ma2ul: impossible error %d", s);
  601. X   }
  602. Xif (((bStrT *) NULL) != end) *end = ep;
  603. Xreturn (u);
  604. X}
  605. X
  606. X#ifdef TEST
  607. X#include <howard/usage.h>
  608. X
  609. XMAINVER ("@(#)$Header: ma2ul.c,v 1.3 89/08/12 09:56:17 howard Exp $");
  610. XUSAGE ("integer-numeric-literal [limit]");
  611. X
  612. XPUBLIC int main (argc, argv)
  613. Xint    argc; /* Number of arguments.*/
  614. XbStrT *argv; /* Points to array of argument strings.*/
  615. X{
  616. XbStrT end; /* Points to end of string.*/
  617. XulongT u; /* Returned by ma2ul().*/
  618. X
  619. Xif (argc < 2) usage();
  620. Xu = ma2ul (argv[1], (2 == argc) ? NULBSTR : &argv[1][atoi (argv[2])], FALSE,
  621. X          S("integer-numeric-literal"), &end);
  622. XPRINTF ("8#%lo#\t10#%lu#\t16#%lX#\t%s\n", u, u, u, end);
  623. Xmfflush (stdout, "Standard Output");
  624. Xexit (SUCCESS);
  625. X
  626. X#ifdef lint
  627. Xreturn (SUCCESS);
  628. X#endif
  629. X}
  630. X#endif
  631. END_OF_FILE
  632. if test 3081 -ne `wc -c <'ma2ul.c'`; then
  633.     echo shar: \"'ma2ul.c'\" unpacked with wrong size!
  634. fi
  635. # end of 'ma2ul.c'
  636. fi
  637. if test -f 'malf.c' -a "${1}" != "-c" ; then 
  638.   echo shar: Will not clobber existing file \"'malf.c'\"
  639. else
  640. echo shar: Extracting \"'malf.c'\" \(3238 characters\)
  641. sed "s/^X//" >'malf.c' <<'END_OF_FILE'
  642. X/*
  643. X * malf - system error handler
  644. X */
  645. X
  646. X#ifndef lint
  647. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  648. X#endif lint
  649. X
  650. X/*
  651. X * This program is free software; you can redistribute it and/or modify
  652. X * it under the terms of the GNU General Public License version 1,
  653. X * as published by the Free Software Foundation.
  654. X *
  655. X * This program is distributed in the hope that it will be useful,
  656. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  657. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  658. X * GNU General Public License for more details.
  659. X *
  660. X * You should have received a copy of the GNU General Public License
  661. X * along with this program; if not, write to the Free Software
  662. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  663. X */
  664. X
  665. X#include <stdio.h>
  666. X#include <howard/port.h>
  667. X#include <howard/version.h>
  668. X
  669. XMODVER ("@(#)$Header: malf.c,v 1.10 89/08/21 17:50:36 howard Exp $");
  670. X
  671. X#include <howard/registers.i>
  672. X#include <howard/malf.h>
  673. X
  674. XPUBLIC boolT _debug = FALSE;
  675. X
  676. X#ifdef NOVPRINTF
  677. X/*VARARGS2*/
  678. XPUBLIC void malf (x, a, b, c, d, e, f)
  679. Xint   x; /* Exit code (0 = no exit).*/
  680. XcStrT a; /* Format string.*/
  681. X#else  NOVPRINTF
  682. X#include <varargs.h>
  683. X
  684. X/*VARARGS0*/
  685. XPUBLIC void malf (va_alist)
  686. Xva_dcl
  687. X#endif NOVPRINTF
  688. X
  689. X/* Function:
  690. X *    Write error message on standard error and (perhaps) exit.
  691. X */
  692. X{
  693. Xextern bStrT   _progn;        /* Version string.*/
  694. Xextern int     errno;         /* See intro(2).*/
  695. Xextern int     sys_nerr;      /* Maximum value of errno for which a
  696. X                   * text entry exists.*/
  697. Xextern cStrT   sys_errlist[]; /* Array of pointers to system error
  698. X                   * text, indexed by errno.*/
  699. Xextern cStrT   ctime();       /* (3).*/
  700. Xextern long    time();        /* (3C).*/
  701. XR1     int     se = errno;    /* Save errno.*/
  702. X       long    ut;            /* Current system time.*/
  703. X#ifndef NOVPRINTF
  704. X       va_list args;
  705. XR2     int     x;             /* Exit code (0 = no exit).*/
  706. XR3     cStrT   a;             /* Format string.*/
  707. X
  708. Xva_start (args);
  709. Xx = va_arg (args, int);
  710. Xa = va_arg (args, cStrT);
  711. X#endif NOVPRINTF
  712. X
  713. XFFLUSH (stdout);
  714. XFPUTS ((0 == x) ? "\nWarning" : "\nError", stderr);
  715. Xif (isatty (fileno (stderr)))
  716. X   {
  717. X   FPUTS (": ", stderr);
  718. X   putspn();
  719. X   }
  720. Xelse
  721. X   {
  722. X   ut = time ((long *) NULL);
  723. X   FPRINTF (stderr, " message at %s", ctime (&ut));
  724. X   if (NULBSTR != _progn) FPRINTF (stderr, "   from: %s\n   ", _progn);
  725. X   }
  726. X
  727. X#ifdef NOVPRINTF
  728. XFPRINTF (stderr, a, b, c, d, e, f);
  729. X#else  NOVPRINTF
  730. X(void) vfprintf (stderr, a, args);
  731. Xva_end (args);
  732. X#endif NOVPRINTF
  733. X
  734. XPUTC ('\n', stderr);
  735. Xif (0 != se)
  736. X   {
  737. X   FPRINTF (stderr, "   System message %d", se);
  738. X   if ((0 < se) && (se <= sys_nerr)) FPRINTF (stderr, ": %s", sys_errlist[se]);
  739. X   PUTC ('\n', stderr);
  740. X   }
  741. XFFLUSH (stderr);
  742. Xif (0 != x)
  743. X   {
  744. X   if (_debug) abort();
  745. X   exit (x);
  746. X   }
  747. Xerrno = 0;
  748. X}
  749. X
  750. X#ifdef TEST
  751. X#include <howard/usage.h>
  752. X
  753. XMAINVER ("@(#)$Header: malf.c,v 1.10 89/08/21 17:50:36 howard Exp $");
  754. XUSAGE ("");
  755. X
  756. XPUBLIC int main (argc, argv)
  757. Xint    argc; /* Number of arguments.*/
  758. XbStrT *argv; /* Points to array of argument strings.*/
  759. X{
  760. Xextern int errno;
  761. Xextern int sys_nerr;
  762. X
  763. Xerrno = 1;
  764. Xmalf (0, "%c %s %d %ld %f", '1', "2", 3, 4L, 5.0);
  765. Xerrno = 1 + sys_nerr;
  766. X_debug = TRUE;
  767. Xmalf (127, "%c %s %d %ld %f", '6', "7", 8, 9L, 10.0);
  768. X}
  769. X#endif
  770. END_OF_FILE
  771. if test 3238 -ne `wc -c <'malf.c'`; then
  772.     echo shar: \"'malf.c'\" unpacked with wrong size!
  773. fi
  774. # end of 'malf.c'
  775. fi
  776. if test -f 'mkLibcLims.b' -a "${1}" != "-c" ; then 
  777.   echo shar: Will not clobber existing file \"'mkLibcLims.b'\"
  778. else
  779. echo shar: Extracting \"'mkLibcLims.b'\" \(3641 characters\)
  780. sed "s/^X//" >'mkLibcLims.b' <<'END_OF_FILE'
  781. X  
  782. X# mkLibcLims - make the libc-lims.i include file for this system
  783. X#
  784. X# $Header: mkLibcLims.b,v 1.8 89/09/21 19:22:37 howard Exp $
  785. X#
  786. X# Copyright 1989 Howard Lee Gayle
  787. X# This file is written in the ISO 8859/1 character set.
  788. X#
  789. X# This program is free software; you can redistribute it and/or modify
  790. X# it under the terms of the GNU General Public License version 1,
  791. X# as published by the Free Software Foundation.
  792. X#
  793. X# This program is distributed in the hope that it will be useful,
  794. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  795. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  796. X# GNU General Public License for more details.
  797. X#
  798. X# You should have received a copy of the GNU General Public License
  799. X# along with this program; if not, write to the Free Software
  800. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  801. X#
  802. X# Shell variables:
  803. X# c - full path to libc.a
  804. X# t - temporary file
  805. X# u - usage string
  806. X
  807. XCMDNAME=mkLibcLims
  808. Xexport CMDNAME
  809. Xu='Usage: $CMDNAME libc-lims.i'
  810. Xif [ $# -ne 1 ]
  811. Xthen
  812. X   echo "$u" 1>&2
  813. X   exit 1
  814. Xfi
  815. Xif [ -r /lib/libc.a ]
  816. Xthen
  817. X   c=/lib/libc.a
  818. Xelif [ -r /usr/lib/libc.a ]
  819. Xthen
  820. X   c=/usr/lib/libc.a
  821. Xelse
  822. X   echo 'mkLibcLims: can not find libc.a' 1>&2
  823. X   exit 1
  824. Xfi
  825. Xt=/tmp/libc$$
  826. Xnm $c 2>/dev/null | sed -n -e 's/^.* T _//p' -e 's/^.* T //p' > $t
  827. Xif grep '^printf$' $t > /dev/null 2>&1
  828. Xthen
  829. X   :
  830. Xelse
  831. X   nm $c 2>/dev/null | sed -n -e 's/^.* D _//p' -e 's/^.* D //p' > $t
  832. X   if grep '^printf$' $t > /dev/null 2>&1
  833. X   then
  834. X      :
  835. X   else
  836. X      ar t $c | sed -e 's/\.o$//' > $f
  837. X      if grep '^printf$' $t > /dev/null 2>&1
  838. X      then
  839. X         :
  840. X      else
  841. X         echo "mkLibcLims: can not list contents of $c" 1>&2
  842. X         exit 1
  843. X      fi
  844. X   fi
  845. Xfi
  846. Xecho '/*' > $1
  847. Xecho ' * libc-lims.i - C library limitations file' >> $1
  848. Xecho ' *' >> $1
  849. Xecho ' * This file was generated automatically by:' >> $1
  850. Xecho ' *    $Header: mkLibcLims.b,v 1.8 89/09/21 19:22:37 howard Exp $' >> $1
  851. Xecho ' */' >> $1
  852. Xecho '' >> $1
  853. X
  854. Xif grep '^drand48$' $t > /dev/null 2>&1
  855. Xthen
  856. X   echo '/*#define NODRAND48 1 /* Comment in if no drand48() function.*/' >> $1
  857. Xelse
  858. X   echo   '#define NODRAND48 1 /* Comment in if no drand48() function.*/' >> $1
  859. Xfi
  860. X
  861. Xif grep '^getopt$' $t > /dev/null 2>&1
  862. Xthen
  863. X   echo '/*#define NOGETOPT 1 /* Comment in if no getopt() function.*/' >> $1
  864. Xelse
  865. X   echo   '#define NOGETOPT 1 /* Comment in if no getopt() function.*/' >> $1
  866. Xfi
  867. X
  868. Xif grep '^memcmp$' $t > /dev/null 2>&1
  869. Xthen
  870. X   echo '/*#define NOMEMCMP 1 /* Comment in if no memcmp() function.*/' >> $1
  871. Xelse
  872. X   echo   '#define NOMEMCMP 1 /* Comment in if no memcmp() function.*/' >> $1
  873. Xfi
  874. X
  875. Xif grep '^random$' $t > /dev/null 2>&1
  876. Xthen
  877. X   echo '/*#define NORANDOM 1 /* Comment in if no random() function.*/' >> $1
  878. Xelse
  879. X   echo   '#define NORANDOM 1 /* Comment in if no random() function.*/' >> $1
  880. Xfi
  881. X
  882. Xif grep '^rename$' $t > /dev/null 2>&1
  883. Xthen
  884. X   echo '/*#define NORENAME 1 /* Comment in if no rename() function.*/' >> $1
  885. Xelse
  886. X   echo   '#define NORENAME 1 /* Comment in if no rename() function.*/' >> $1
  887. Xfi
  888. X
  889. Xif grep '^strchr$' $t > /dev/null 2>&1
  890. Xthen
  891. X   echo '/*#define NOSTRCHR 1 /* Comment in if no strchr() function.*/' >> $1
  892. Xelse
  893. X   echo   '#define NOSTRCHR 1 /* Comment in if no strchr() function.*/' >> $1
  894. Xfi
  895. X
  896. Xif grep '^strspn$' $t > /dev/null 2>&1
  897. Xthen
  898. X   echo '/*#define NOSTRSPN 1 /* Comment in if no strspn() function.*/' >> $1
  899. Xelse
  900. X   echo   '#define NOSTRSPN 1 /* Comment in if no strspn() function.*/' >> $1
  901. Xfi
  902. X
  903. Xif grep '^vprintf$' $t > /dev/null 2>&1
  904. Xthen
  905. X   echo '/*#define NOVPRINTF 1 /* Comment in if no vprintf() function.*/' >> $1
  906. Xelse
  907. X   echo   '#define NOVPRINTF 1 /* Comment in if no vprintf() function.*/' >> $1
  908. Xfi
  909. Xrm $t
  910. END_OF_FILE
  911. if test 3641 -ne `wc -c <'mkLibcLims.b'`; then
  912.     echo shar: \"'mkLibcLims.b'\" unpacked with wrong size!
  913. fi
  914. # end of 'mkLibcLims.b'
  915. fi
  916. if test -f 'msgfn.c' -a "${1}" != "-c" ; then 
  917.   echo shar: Will not clobber existing file \"'msgfn.c'\"
  918. else
  919. echo shar: Extracting \"'msgfn.c'\" \(3515 characters\)
  920. sed "s/^X//" >'msgfn.c' <<'END_OF_FILE'
  921. X/*
  922. X * msgfn - Extract full name from mail message or news article header
  923. X */
  924. X
  925. X#ifndef lint
  926. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  927. X#endif lint
  928. X
  929. X/*
  930. X * This program is free software; you can redistribute it and/or modify
  931. X * it under the terms of the GNU General Public License version 1,
  932. X * as published by the Free Software Foundation.
  933. X *
  934. X * This program is distributed in the hope that it will be useful,
  935. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  936. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  937. X * GNU General Public License for more details.
  938. X *
  939. X * You should have received a copy of the GNU General Public License
  940. X * along with this program; if not, write to the Free Software
  941. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  942. X */
  943. X
  944. X#include <stdio.h>
  945. X#include <howard/port.h>
  946. X#include <howard/version.h>
  947. X
  948. XMODVER ("@(#)$Header: msgfn.c,v 1.2 89/08/19 10:19:10 howard Exp $");
  949. X
  950. X#include <string.h>
  951. X#include <howard/malf.h>
  952. X#include <howard/registers.i>
  953. X
  954. XPUBLIC boolT msgfn (s, b)
  955. XR3 bStrT s; /* String containing an address field.*/
  956. XR4 bStrT b; /* Buffer in which to store result.*/
  957. X
  958. X/* Function:
  959. X *    
  960. X * Algorithm:
  961. X *    If there's something in double quotes, copy what's in the leftmost pair.
  962. X *    If there's something in parentheses, copy what's in the leftmost pair.
  963. X *    If there's something in angle brackets, copy everything else,
  964. X *    except leading and trailing spaces.
  965. X * Returns:
  966. X *    TRUE iff a full name was copied.
  967. X * Notes:
  968. X *    1) What's in double quotes isn't always a full name, but it's a good bet.
  969. X */
  970. X{
  971. XR1 bStrT p1; /* Points to first delimiter.*/
  972. XR2 bStrT p2; /* Points to second delimiter.*/
  973. X
  974. Xif (NULBSTR == s) malf1 ("msgfn: no input");
  975. Xif (NULBSTR == b) malf1 ("msgfn: no output");
  976. Xp1 = bStrChr (s, '"');
  977. Xif (NULBSTR != p1)
  978. X   {
  979. X   ++p1;
  980. X   p2 = bStrChr (p1, '"');
  981. X   if ((NULBSTR != p2) && (p1 != p2))
  982. X      {
  983. X      STRNCPY ((cStrT) b, (cStrT) p1, p2 - p1);
  984. X      return (TRUE);
  985. X      }
  986. X   }
  987. Xp1 = bStrChr (s, '(');
  988. Xif (NULBSTR != p1)
  989. X   {
  990. X   ++p1;
  991. X   p2 = bStrChr (p1, ')');
  992. X   if ((NULBSTR != p2) && (p1 != p2))
  993. X      {
  994. X      STRNCPY ((cStrT) b, (cStrT) p1, p2 - p1);
  995. X      return (TRUE);
  996. X      }
  997. X   }
  998. Xp1 = bStrChr (s, '<');
  999. Xif (NULBSTR != p1)
  1000. X   {
  1001. X   p2 = bStrChr (p1 + 1, '>');
  1002. X   if ((NULBSTR != p2) && ((p1 + 1) != p2))
  1003. X      {
  1004. X      while (' ' == B(*s))
  1005. X         ++s;
  1006. X      if (s != p1) STRNCPY ((cStrT) b, (cStrT) s, p1 - s);
  1007. X      p1 = p2 + 1;
  1008. X      for (p2 = strend (p1); ' ' == B(p2[-1]); --p2)
  1009. X         ;
  1010. X      if (p1 != p2) STRNCAT ((cStrT) b, (cStrT) p1, p2 - p1);
  1011. X      return (TRUE);
  1012. X      }
  1013. X   }
  1014. Xreturn (FALSE);
  1015. X}
  1016. X
  1017. X#ifdef TEST
  1018. X#include <howard/usage.h>
  1019. X
  1020. XMAINVER ("@(#)$Header: msgfn.c,v 1.2 89/08/19 10:19:10 howard Exp $");
  1021. XUSAGE ("");
  1022. X
  1023. X
  1024. XPRIVATE void t (n, s, xr, xb)
  1025. Xint n; /* Test number.*/
  1026. XbStrT s; /* Test string.*/
  1027. XboolT xr; /* Expected return.*/
  1028. XbStrT xb; /* Expected stored result.*/
  1029. X{
  1030. XbyteT b[1024]; /* Store result here.*/
  1031. X
  1032. Xif (xr != msgfn (s, b))
  1033. X   PRINTF ("%d: rc %d expected\n", n, xr);
  1034. Xelse if (xr && !bStrEQ (b, xb))
  1035. X   PRINTF ("%d: result %s expected %s\n", n, b, xb);
  1036. X}
  1037. X
  1038. XPUBLIC int main ()
  1039. X{
  1040. Xt(__LINE__, S("\"Howard Gayle\"@ericsson.se"), TRUE, S("Howard Gayle"));
  1041. Xt(__LINE__, S("howard@ericsson.se (Howard Gayle)"), TRUE, S("Howard Gayle"));
  1042. Xt(__LINE__, S("Howard Gayle<howard@ericsson.se>"), TRUE, S("Howard Gayle"));
  1043. Xt(__LINE__, S("howard@ericsson.se"), FALSE, NULBSTR);
  1044. Xmfflush (stdout, S("Standard Output"));
  1045. Xexit (SUCCESS);
  1046. X
  1047. X#ifdef lint
  1048. Xreturn (SUCCESS);
  1049. X#endif
  1050. X}
  1051. X#endif
  1052. END_OF_FILE
  1053. if test 3515 -ne `wc -c <'msgfn.c'`; then
  1054.     echo shar: \"'msgfn.c'\" unpacked with wrong size!
  1055. fi
  1056. # end of 'msgfn.c'
  1057. fi
  1058. if test -f 'smp.3' -a "${1}" != "-c" ; then 
  1059.   echo shar: Will not clobber existing file \"'smp.3'\"
  1060. else
  1061. echo shar: Extracting \"'smp.3'\" \(3670 characters\)
  1062. sed "s/^X//" >'smp.3' <<'END_OF_FILE'
  1063. X.\" $Header: smp.3,v 1.3 89/08/15 14:53:10 howard Exp $
  1064. X.TH SMP "3 -lhoward" "$Revision: 1.3 $" "Howard\'s C library" "Howard\'s C library"
  1065. X.SH NAME
  1066. Xa2smp, mk-smp, smp2l, smp2u, smp2ul, smpdig, smpdtl \- simple multiple precision system
  1067. X.SH SYNOPSIS
  1068. X.B mk-smp
  1069. X.LP
  1070. X.nf
  1071. X.BR "#include <" stdio.h ">"
  1072. X.BR "#include <" howard/port.h ">"
  1073. X.BR "#include <" howard/simultipre.i ">"
  1074. X.BR "#include <" howard/smp.h ">"
  1075. X.fi
  1076. X.LP
  1077. X.BR "int " "a2smp ("
  1078. X.IR string ,
  1079. X.IR limit ,
  1080. X.IR looseSyntax ,
  1081. X.IR resultPointer ,
  1082. X.IR endPointer " )"
  1083. X.nf
  1084. X.RI "bStrT " string ";"
  1085. X.RI "bStrT " limit ";"
  1086. X.RI "boolT " looseSyntax ";"
  1087. X.RI "smpT *" resultPointer;
  1088. X.RI "bStrT *" endPointer ;
  1089. X.fi
  1090. X.LP
  1091. X.BR "int " "smp2l ("
  1092. X.IR smpPtr ,
  1093. X.IR longPtr )
  1094. X.nf
  1095. X.RI "smpT *" smpPtr ;
  1096. X.BI "long *" longPtr;
  1097. X.fi
  1098. X.LP
  1099. X.BR "int " "smp2u ("
  1100. X.IR smpPtr ,
  1101. X.IR unsignedPtr )
  1102. X.nf
  1103. X.RI "smpT *" smpPtr ;
  1104. X.BI "unsigned *" unsignedPtr;
  1105. X.fi
  1106. X.LP
  1107. X.BR "int " "smp2ul ("
  1108. X.IR smpPtr ,
  1109. X.IR ulongTPtr )
  1110. X.nf
  1111. X.RI "smpT *" smpPtr ;
  1112. X.RI "ulongT *" ulongTPtr ;
  1113. X.fi
  1114. X.LP
  1115. XboolT smpdig (
  1116. X.IR digit ,
  1117. X.IR radix ,
  1118. X.IR smpPtr )
  1119. X.nf
  1120. X.BI "int " digit;
  1121. X.BI "unsigned " radix;
  1122. X.RI "smpT *" smpPtr ;
  1123. X.fi
  1124. X.LP
  1125. X.BR "int " "smpdtl ("
  1126. X.IR chr ,
  1127. X.IR digitTable )
  1128. X.nf
  1129. X.RI "rcharT " chr ;
  1130. X.RI "bStrT *" digitTable ;
  1131. X.fi
  1132. X.SH COPYRIGHT
  1133. XCopyright \(co 1989 Howard Lee Gayle
  1134. X.SH DESCRIPTION
  1135. XThese functions provide a very simple multiple precision (SMP)
  1136. Xfacility for use in converting string representations of
  1137. Xinteger numeric literals to internal representations while
  1138. Xchecking for overflow.
  1139. XSMPs can represent numbers enough bigger than the biggest
  1140. Xinternal representation (typically unsigned long) to detect
  1141. Xoverflow.
  1142. X.PP
  1143. XThe
  1144. X.I mk-smp
  1145. Xcommand chooses a representation automatically based on the
  1146. Xlimits.h include file, and outputs another include file,
  1147. Xsimultipre.i, which defines the representation.
  1148. X.PP
  1149. X.I a2smp
  1150. Xconverts Ada-syntax integer numeric literals to simple multiple
  1151. Xprecision (SMP) numbers.
  1152. XSee
  1153. X.IR a2 (3).
  1154. X.PP
  1155. X.I smp2l
  1156. Xtries to convert the simple multiple precision number to which
  1157. X.I smpPtr
  1158. Xpoints to a long.
  1159. XIf
  1160. X.I longPtr
  1161. Xis not NULL, then the result is stored in the area to which
  1162. X.I longPtr
  1163. Xpoints.
  1164. X.I smp2l
  1165. Xreturns 0 on success, EINVAL on invalid arguments, and ERANGE
  1166. Xon overflow.
  1167. X.I smp2u
  1168. Xis the corresponding function for unsigned.
  1169. X.I smp2ul
  1170. Xis the corresponding function for unsigned long.
  1171. X.PP
  1172. X.I smpdig
  1173. Xperforms the operation
  1174. X.nf
  1175. X   smp = smp * radix + digit;
  1176. X.fi
  1177. Xwhere smp is the simple multiple precision number to which
  1178. X.I smpPtr
  1179. Xpoints.
  1180. X.I smpdig
  1181. Xreturns TRUE on success and FALSE on overflow.
  1182. X.PP
  1183. X.I smpdtl
  1184. Xsearches a digit table for character
  1185. X.IR chr .
  1186. XA digit table is an array of strings, where each string
  1187. Xcontains all the possible characters representing that digit.
  1188. XOn a match,
  1189. X.I smpdtl
  1190. Xreturns the index in the digit table at which the match occurred;
  1191. Xotherwise it returns -1.
  1192. X.SH "SEE ALSO"
  1193. X.IR a2 "(3 \-lhoward)."
  1194. X.SH LICENSE
  1195. XThis program is free software; you can redistribute it and/or modify
  1196. Xit under the terms of the GNU General Public License version 1,
  1197. Xas published by the Free Software Foundation.
  1198. X.PP
  1199. XThis program is distributed in the hope that it will be useful,
  1200. Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
  1201. XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1202. XGNU General Public License for more details.
  1203. X.PP
  1204. XYou should have received a copy of the GNU General Public License
  1205. Xalong with this program; if not, write to the Free Software
  1206. XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1207. X.SH AUTHOR
  1208. XHoward Gayle,
  1209. XTN/ETX/T/BG,
  1210. XEricsson Telecom AB,
  1211. XS-126 25 Stockholm,
  1212. XSweden,
  1213. Xhoward@ericsson.se,
  1214. Xuunet!ericsson.se!howard,
  1215. XPhone: +46 8 719 5565,
  1216. XFAX: +46 8 719 9598,
  1217. XTelex: 14910 ERIC S
  1218. END_OF_FILE
  1219. if test 3670 -ne `wc -c <'smp.3'`; then
  1220.     echo shar: \"'smp.3'\" unpacked with wrong size!
  1221. fi
  1222. # end of 'smp.3'
  1223. fi
  1224. if test -f 'smp2l.c' -a "${1}" != "-c" ; then 
  1225.   echo shar: Will not clobber existing file \"'smp2l.c'\"
  1226. else
  1227. echo shar: Extracting \"'smp2l.c'\" \(3330 characters\)
  1228. sed "s/^X//" >'smp2l.c' <<'END_OF_FILE'
  1229. X/*
  1230. X * smp2l - convert simple multiple precision number to long
  1231. X */
  1232. X
  1233. X#ifndef lint
  1234. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  1235. X#endif lint
  1236. X
  1237. X/*
  1238. X * This program is free software; you can redistribute it and/or modify
  1239. X * it under the terms of the GNU General Public License version 1,
  1240. X * as published by the Free Software Foundation.
  1241. X *
  1242. X * This program is distributed in the hope that it will be useful,
  1243. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1244. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1245. X * GNU General Public License for more details.
  1246. X *
  1247. X * You should have received a copy of the GNU General Public License
  1248. X * along with this program; if not, write to the Free Software
  1249. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1250. X */
  1251. X
  1252. X#include <stdio.h>
  1253. X#include <howard/port.h>
  1254. X#include <howard/version.h>
  1255. X
  1256. XMODVER ("@(#)$Header: smp2l.c,v 1.9 89/08/14 18:20:04 howard Exp $");
  1257. X
  1258. X#include <errno.h>
  1259. X#include <limits.h>
  1260. X#include <howard/registers.i>
  1261. X#include <howard/simultipre.i>
  1262. X#include <howard/smp.h>
  1263. X
  1264. XPUBLIC int smp2l (sp, lp)
  1265. XR4 smpT *sp; /* Points to SMP.*/
  1266. XR5 long *lp; /* Points to where to store result.*/
  1267. X
  1268. X/* Function:
  1269. X *    
  1270. X * Algorithm:
  1271. X *    Check for max negative number as special case.
  1272. X *    Check for overflow.  Or each part of smp into res.
  1273. X *    Negate if necessary.
  1274. X * Returns:
  1275. X *    
  1276. X * Notes:
  1277. X *    
  1278. X */
  1279. X{
  1280. XR3     long    res;               /* Result.*/
  1281. XR1     smpElT *p1;                /* Steps through sp->smp_el[].*/
  1282. XR2     smpElT *p2;                /* Most significant element.*/
  1283. Xstatic smpT    smpMinL = SMPLMIN; /* LONG_MIN in SMP format.*/
  1284. X
  1285. Xif (((smpT *) NULL) == sp) return (EINVAL);
  1286. Xif (0 == memcmp ((cStrT) sp, (cStrT) &smpMinL, sizeof (smpT)))
  1287. X   res = LONG_MIN;
  1288. Xelse
  1289. X   {
  1290. X   p2 = &sp->smp_el[SMPNL - 1];
  1291. X   for (p1 = &sp->smp_el[SMPNEL - 1]; p1 != p2;)
  1292. X      if (0 != *p1--) return (ERANGE);
  1293. X   if (0 != (*p1 >> SMPLHB)) return (ERANGE);
  1294. X   for (res = 0L; p1 >= sp->smp_el; --p1)
  1295. X      res = (res << SMPEB) | *p1;
  1296. X   if (sp->smp_neg) res = -res;
  1297. X   }
  1298. Xif (((long *) NULL) != lp) *lp = res;
  1299. Xreturn (SUCCESS);
  1300. X}
  1301. X
  1302. X#ifdef TEST
  1303. X#include <howard/usage.h>
  1304. X
  1305. XMAINVER ("@(#)$Header: smp2l.c,v 1.9 89/08/14 18:20:04 howard Exp $");
  1306. XUSAGE ("");
  1307. X
  1308. X#include <howard/malf.h>
  1309. X
  1310. XPRIVATE void t (num, neg, hi, lo, xrc, xres)
  1311. Xint num; /* Test number.*/
  1312. XboolT neg; /* smp_neg */
  1313. XsmpElT hi; /* smp_el[1] */
  1314. XsmpElT lo; /* smp_el[0] */
  1315. Xint xrc; /* Expected return code.*/
  1316. Xlong xres; /* Expected result.*/
  1317. X{
  1318. Xint rc; /* Return code.*/
  1319. Xlong res; /* Result stored here.*/
  1320. XsmpT smp; /* SMP argument.*/
  1321. X
  1322. Xsmp.smp_neg = neg;
  1323. Xsmp.smp_el[0] = lo;
  1324. Xsmp.smp_el[1] = hi;
  1325. Xrc = smp2l (&smp, &res);
  1326. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  1327. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  1328. X   PRINTF ("%d: res %lX expected %lX\n", num, res, xres);
  1329. X}
  1330. X
  1331. XPUBLIC int main ()
  1332. X{
  1333. Xt(__LINE__, 0,      0,      0,      0,            0L);
  1334. Xt(__LINE__, 1, 0x8000,      0,      0,(long)LONG_MIN);
  1335. Xt(__LINE__, 0, 0x8000,      1, ERANGE,            0L);
  1336. Xt(__LINE__, 1, 0x7FFF, 0xFFFF,      0, LONG_MIN + 1L);
  1337. Xt(__LINE__, 1,      0,      1,      0,           -1L);
  1338. Xt(__LINE__, 0,      0,      1,      0,            1L);
  1339. Xt(__LINE__, 0, 0x7FFF, 0xFFFF,      0,(long)LONG_MAX);
  1340. X
  1341. Xmfflush (stdout, "Standard Output");
  1342. Xexit (SUCCESS);
  1343. X
  1344. X#ifdef lint
  1345. Xreturn (SUCCESS);
  1346. X#endif
  1347. X}
  1348. X#endif
  1349. END_OF_FILE
  1350. if test 3330 -ne `wc -c <'smp2l.c'`; then
  1351.     echo shar: \"'smp2l.c'\" unpacked with wrong size!
  1352. fi
  1353. # end of 'smp2l.c'
  1354. fi
  1355. if test -f 'smp2u.c' -a "${1}" != "-c" ; then 
  1356.   echo shar: Will not clobber existing file \"'smp2u.c'\"
  1357. else
  1358. echo shar: Extracting \"'smp2u.c'\" \(3463 characters\)
  1359. sed "s/^X//" >'smp2u.c' <<'END_OF_FILE'
  1360. X/*
  1361. X * smp2ul - convert simple multiple precision number to unsigned
  1362. X */
  1363. X
  1364. X#ifndef lint
  1365. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  1366. X#endif lint
  1367. X
  1368. X/*
  1369. X * This program is free software; you can redistribute it and/or modify
  1370. X * it under the terms of the GNU General Public License version 1,
  1371. X * as published by the Free Software Foundation.
  1372. X *
  1373. X * This program is distributed in the hope that it will be useful,
  1374. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1375. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1376. X * GNU General Public License for more details.
  1377. X *
  1378. X * You should have received a copy of the GNU General Public License
  1379. X * along with this program; if not, write to the Free Software
  1380. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1381. X */
  1382. X
  1383. X#include <stdio.h>
  1384. X#include <howard/port.h>
  1385. X#include <howard/version.h>
  1386. X
  1387. XMODVER ("@(#)$Header: smp2u.c,v 1.2 89/08/14 18:29:32 howard Exp $");
  1388. X
  1389. X#include <errno.h>
  1390. X#include <limits.h>
  1391. X#include <howard/registers.i>
  1392. X#include <howard/simultipre.i>
  1393. X#include <howard/smp.h>
  1394. X
  1395. XPUBLIC int smp2u (sp, lp)
  1396. XR1 smpT     *sp; /* Points to SMP.*/
  1397. XR5 unsigned *lp; /* Points to where to store result.*/
  1398. X
  1399. X/* Function:
  1400. X *    
  1401. X * Algorithm:
  1402. X *    Step downward through higher order SMP elements that ought to
  1403. X *    be zero, and make sure they are.  Make sure high order bits in
  1404. X *    the highest order element are also zero.  Or each element into
  1405. X *    the result.  Check for a negative result.  Store the result.
  1406. X * Returns:
  1407. X *    
  1408. X * Notes:
  1409. X *    
  1410. X */
  1411. X{
  1412. XR4 unsigned res = 0; /* Result.*/
  1413. XR2 smpElT  *p1;      /* Steps through sp->smp_el[].*/
  1414. XR3 smpElT  *p2;      /* Highest order smp_el used.*/
  1415. X
  1416. Xif (((smpT *) NULL) == sp) return (EINVAL);
  1417. Xp2 = &sp->smp_el[SMPNU - 1];
  1418. Xfor (p1 = &sp->smp_el[SMPNEL - 1]; p1 != p2; --p1)
  1419. X   if (0 != *p1) return (ERANGE);
  1420. Xif (0 != (*p1 >> SMPUHB)) return (ERANGE);
  1421. Xwhile (p1 >= sp->smp_el)
  1422. X   res = (res << SMPEB) | *p1--;
  1423. Xif (sp->smp_neg && (0 != res)) return (ERANGE);
  1424. Xif (((unsigned *) NULL) != lp) *lp = res;
  1425. Xreturn (SUCCESS);
  1426. X}
  1427. X
  1428. X#ifdef TEST
  1429. X#include <howard/usage.h>
  1430. X
  1431. XMAINVER ("@(#)$Header: smp2u.c,v 1.2 89/08/14 18:29:32 howard Exp $");
  1432. XUSAGE ("");
  1433. X
  1434. X#include <howard/malf.h>
  1435. X
  1436. XPRIVATE void t (num, neg, hi, lo, xrc, xres)
  1437. Xint   num; /* Test number.*/
  1438. XboolT neg; /* smp_neg */
  1439. XsmpElT hi; /* smp_el[1] */
  1440. XsmpElT lo; /* smp_el[0] */
  1441. Xint   xrc; /* Expected return code.*/
  1442. Xunsigned xres; /* Expected result.*/
  1443. X{
  1444. Xint rc; /* Return code.*/
  1445. Xunsigned res; /* Result stored here.*/
  1446. XsmpT smp; /* SMP argument.*/
  1447. X
  1448. Xsmp.smp_neg = neg;
  1449. Xsmp.smp_el[0] = lo;
  1450. Xsmp.smp_el[1] = hi;
  1451. Xrc = smp2u (&smp, &res);
  1452. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  1453. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  1454. X   PRINTF ("%d: res %X expected %X\n", num, res, xres);
  1455. X}
  1456. X
  1457. XPUBLIC int main ()
  1458. X{
  1459. X/* num    sgn   hi      lo      rc         res   */
  1460. Xt(__LINE__, 0,      0,      0,      0, (unsigned)           0);
  1461. Xt(__LINE__, 1,      0,      0,      0, (unsigned)           0);
  1462. Xt(__LINE__, 0,      0,      1,      0, (unsigned)           1);
  1463. Xt(__LINE__, 0, 0x7FFF, 0xFFFF,      0, (unsigned)  0x7FFFFFFF);
  1464. Xt(__LINE__, 0, 0x8000,      0,      0, (unsigned)  0x80000000);
  1465. Xt(__LINE__, 0, 0xFFFF, 0xFFFF,      0, (unsigned)  0xFFFFFFFF);
  1466. Xt(__LINE__, 0,0x10000, 0x0000, ERANGE, (unsigned)           0);
  1467. Xt(__LINE__, 1,      0,      1, ERANGE, (unsigned)           0);
  1468. X
  1469. Xmfflush (stdout, "Standard Output");
  1470. Xexit (SUCCESS);
  1471. X
  1472. X#ifdef lint
  1473. Xreturn (SUCCESS);
  1474. X#endif
  1475. X}
  1476. X#endif
  1477. END_OF_FILE
  1478. if test 3463 -ne `wc -c <'smp2u.c'`; then
  1479.     echo shar: \"'smp2u.c'\" unpacked with wrong size!
  1480. fi
  1481. # end of 'smp2u.c'
  1482. fi
  1483. if test -f 'smp2ul.c' -a "${1}" != "-c" ; then 
  1484.   echo shar: Will not clobber existing file \"'smp2ul.c'\"
  1485. else
  1486. echo shar: Extracting \"'smp2ul.c'\" \(3441 characters\)
  1487. sed "s/^X//" >'smp2ul.c' <<'END_OF_FILE'
  1488. X/*
  1489. X * smp2ul - convert simple multiple precision number to unsigned long
  1490. X */
  1491. X
  1492. X#ifndef lint
  1493. Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle";
  1494. X#endif lint
  1495. X
  1496. X/*
  1497. X * This program is free software; you can redistribute it and/or modify
  1498. X * it under the terms of the GNU General Public License version 1,
  1499. X * as published by the Free Software Foundation.
  1500. X *
  1501. X * This program is distributed in the hope that it will be useful,
  1502. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1503. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1504. X * GNU General Public License for more details.
  1505. X *
  1506. X * You should have received a copy of the GNU General Public License
  1507. X * along with this program; if not, write to the Free Software
  1508. X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1509. X */
  1510. X
  1511. X#include <stdio.h>
  1512. X#include <howard/port.h>
  1513. X#include <howard/version.h>
  1514. X
  1515. XMODVER ("@(#)$Header: smp2ul.c,v 1.7 89/08/15 11:14:04 howard Exp $");
  1516. X
  1517. X#include <errno.h>
  1518. X#include <limits.h>
  1519. X#include <howard/registers.i>
  1520. X#include <howard/simultipre.i>
  1521. X#include <howard/smp.h>
  1522. X
  1523. XPUBLIC int smp2ul (sp, lp)
  1524. XR1 smpT   *sp; /* Points to SMP.*/
  1525. XR5 ulongT *lp; /* Points to where to store result.*/
  1526. X
  1527. X/* Function:
  1528. X *    
  1529. X * Algorithm:
  1530. X *    Step downward through higher order SMP elements that ought to
  1531. X *    be zero, and make sure they are.  Make sure high order bits in
  1532. X *    the highest order element are also zero.  Or each element into
  1533. X *    the result.  Check for a negative result.  Store the result.
  1534. X * Returns:
  1535. X *    
  1536. X * Notes:
  1537. X *    
  1538. X */
  1539. X{
  1540. XR4 ulongT  res = 0; /* Result.*/
  1541. XR2 smpElT *p1;      /* Steps through sp->smp_el[].*/
  1542. XR3 smpElT *p2;      /* Highest order smp_el used..*/
  1543. X
  1544. Xif (((smpT *) NULL) == sp) return (EINVAL);
  1545. Xp2 = &sp->smp_el[SMPNUL - 1];
  1546. Xfor (p1 = &sp->smp_el[SMPNEL - 1]; p1 != p2;)
  1547. X   if (0 != *p1--) return (ERANGE);
  1548. Xif (0 != (*p1 >> SMPULHB)) return (ERANGE);
  1549. Xwhile (p1 >= sp->smp_el)
  1550. X   res = (res << SMPEB) | *p1--;
  1551. Xif (sp->smp_neg && (0 != res)) return (ERANGE);
  1552. Xif (((ulongT *) NULL) != lp) *lp = res;
  1553. Xreturn (SUCCESS);
  1554. X}
  1555. X
  1556. X#ifdef TEST
  1557. X#include <howard/usage.h>
  1558. X
  1559. XMAINVER ("@(#)$Header: smp2ul.c,v 1.7 89/08/15 11:14:04 howard Exp $");
  1560. XUSAGE ("");
  1561. X
  1562. X#include <howard/malf.h>
  1563. X
  1564. XPRIVATE void t (num, neg, hi, lo, xrc, xres)
  1565. Xint num; /* Test number.*/
  1566. XboolT neg; /* smp_neg */
  1567. XsmpElT hi; /* smp_el[1] */
  1568. XsmpElT lo; /* smp_el[0] */
  1569. Xint xrc; /* Expected return code.*/
  1570. XulongT xres; /* Expected result.*/
  1571. X{
  1572. Xint rc; /* Return code.*/
  1573. XulongT res; /* Result stored here.*/
  1574. XsmpT smp; /* SMP argument.*/
  1575. X
  1576. Xsmp.smp_neg = neg;
  1577. Xsmp.smp_el[0] = lo;
  1578. Xsmp.smp_el[1] = hi;
  1579. Xrc = smp2ul (&smp, &res);
  1580. Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc);
  1581. Xif ((0 == rc) && (0 == xrc) && (res != xres))
  1582. X   PRINTF ("%d: res %lX expected %lX\n", num, res, xres);
  1583. X}
  1584. X
  1585. XPUBLIC int main ()
  1586. X{
  1587. X/* num    sgn   hi      lo      rc         res   */
  1588. Xt(__LINE__, 0,      0,      0,      0, (ulongT)           0);
  1589. Xt(__LINE__, 1,      0,      0,      0, (ulongT)           0);
  1590. Xt(__LINE__, 0,      0,      1,      0, (ulongT)           1);
  1591. Xt(__LINE__, 0, 0x7FFF, 0xFFFF,      0, (ulongT)  0x7FFFFFFF);
  1592. Xt(__LINE__, 0, 0x8000,      0,      0, (ulongT)  0x80000000);
  1593. Xt(__LINE__, 0, 0xFFFF, 0xFFFF,      0, (ulongT)  0xFFFFFFFF);
  1594. Xt(__LINE__, 0,0x10000, 0x0000, ERANGE, (ulongT)           0);
  1595. Xt(__LINE__, 1,      0,      1, ERANGE, (ulongT)           0);
  1596. X
  1597. Xmfflush (stdout, "Standard Output");
  1598. Xexit (SUCCESS);
  1599. X
  1600. X#ifdef lint
  1601. Xreturn (SUCCESS);
  1602. X#endif
  1603. X}
  1604. X#endif
  1605. END_OF_FILE
  1606. if test 3441 -ne `wc -c <'smp2ul.c'`; then
  1607.     echo shar: \"'smp2ul.c'\" unpacked with wrong size!
  1608. fi
  1609. # end of 'smp2ul.c'
  1610. fi
  1611. echo shar: End of archive 5 \(of 9\).
  1612. cp /dev/null ark5isdone
  1613. MISSING=""
  1614. for I in 1 2 3 4 5 6 7 8 9 ; do
  1615.     if test ! -f ark${I}isdone ; then
  1616.     MISSING="${MISSING} ${I}"
  1617.     fi
  1618. done
  1619. if test "${MISSING}" = "" ; then
  1620.     echo You have unpacked all 9 archives.
  1621.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1622. else
  1623.     echo You still need to unpack the following archives:
  1624.     echo "        " ${MISSING}
  1625. fi
  1626. ##  End of shell archive.
  1627. exit 0
  1628.  
  1629.